package com.leaf.u_spring.chapter03;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jndi.JndiObjectFactoryBean;

/**
 * 生产环境部署配置类
 *
 */
@Configuration
@Profile("prod")
public class ProductionProfileConfig {

	@Bean
	public DataSource dataSource(){
		JndiObjectFactoryBean jndiObjectFactoryBean = 
				new JndiObjectFactoryBean();
		jndiObjectFactoryBean.setJndiName("jdbc/myDS");
		jndiObjectFactoryBean.setResourceRef(true);
		jndiObjectFactoryBean.setProxyInterface(javax.sql.DataSource.class);
		
		return (DataSource) jndiObjectFactoryBean.getObject();
	}
}
